#ifndef SIMPLELOGGER_H
#define SIMPLELOGGER_H

#include <QObject>
#include <QFile>
#include <QMutex>
#include <QTimer>
#include <QThread>

class SimpleLogger : public QObject
{
    Q_OBJECT
public:
    explicit SimpleLogger(QObject *parent = nullptr);
    void initRollingFileLog();
    static SimpleLogger * getInstance();
    static void consoleOutputMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
    static void rollingFileOutputMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
    qint64 getMaxFileSize();
    void setMaxFileSize(qint64 value);
    qint64 getMaxBackUp();
    void setMaxBackUp(qint64 value);
    QString getLogFileName();
    void setLogFileName(const QString &value);
    QString getLogFilePath();
    void setLogFilePath(const QString &value);

private:
    static SimpleLogger *instance;
    static QMutex instanceLock;
    QFile * currentlogFile = nullptr;
    qint64 currentLogfileSize = 0;
    qint64 maxFileSize = 1024*1024*100;
    qint64 maxBackUp = 3;
    QString logFileName = "simplelogger.log";
    QString logFilePath = "./logs";
    QMutex logLock;
    QTimer timer;

    void initLogFile(QString currentLogFileAbsoluteFilePath);
    void writeLogFile(QString finalMessage);

signals:

public slots:
    void onTimerTimeout();
};

#endif // SIMPLELOGGER_H
